<?php
/*
 * Created on May 14, 2009
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 *
 */

$this->load->view('admin/consultant/link_bar');
?>

<script type="text/javascript" src="{base_url}js/jquery1.6.1.js" ></script>
<script type="text/javascript" src="{base_url}js/ajaxupload.3.5.js" ></script>

<style>
    #upload{
        margin:30px 0px; padding:5px;
        font-weight:bold; font-size:1.3em;
        font-family:Arial, Helvetica, sans-serif;
        text-align:center;
        background:#f2f2f2;
        color:#3366cc;
        border:1px solid #ccc;
        width:150px; height: 20px;
        cursor:pointer !important;
        -moz-border-radius:5px; -webkit-border-radius:5px;
    }
    .darkbg{
        background:#ddd !important;
    }
    #status{
        font-family:Arial; padding:5px;
    }
    div#files{ list-style:none; padding:0; margin:0; }
    div#files div{ padding:5px; margin-bottom:2px; width:120px; float:left; margin-right:5px;}
    div#files div img{ max-width:100px; max-height:100px; }
    .success{ background:#99f099; border:1px solid #339933; }
    .error{ background:#f0c6c3; border:1px solid #cc6622; }
</style>
<script type="text/javascript" >
    function deleteImage(image_id, image_name, consultant_id){
        var url_request = "<?php echo site_url('admin/consultant/delete_image/'); ?>";
        $.ajax({
            type: "POST",
            url: url_request ,
            data: "consultant_id=" + consultant_id + "&image_name="+ image_name ,
            dataType: "json",
            success: function(msg){
                //if(msg.error == false)
                $('#' + image_id).hide(1);
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {

                // $('#waiting').hide(500);
                // $('#message').removeClass().addClass('error').text('There was an error.').show(500);
                // $('#demoForm').show(500);
                alert( "Error: Delete image not successfull." + error.empty);
            }
        });
    }

    $(function(){
        var btnUpload=$('#upload');
        var status=$('#status');
        new AjaxUpload(btnUpload, {
            action: '<?php echo site_url(); ?>admin/consultant/do_upload/{id}',
            name: 'uploadfile',
            onSubmit: function(file, ext){
                if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){
                    // extension is not allowed
                    status.text('Only JPG, PNG or GIF files are allowed');
                    return false;
                }
                status.text('Uploading...');
            },
            onComplete: function(file, response){
                //On completion clear the status
                //alert(response);
                status.text('');
                //Add uploaded file to list
                var msg = jQuery.parseJSON(response);

                //alert(msg.filename);
                //return;
                if(response=="error"){
                    $('<li></li>').appendTo('#files').text(file).addClass('error');
                }
                else{
                    $('<div class ="success" id="'+msg.id+'"></div>').appendTo('#files').html(
                    '<img src="{base_url}data/images/upload/'+
                        msg.filename+'" alt="" height=65 width=65 /><br />'+
                        '<a href="javascript:void();" onclick="insert(\''+msg.filename+ '\', \'vi\');">Insert (Vi)</a>' +
                      
                        ' <a href="javascript:void();" onclick="setImageDefault(\''+msg.filename+ '\', \'{id}\');">Default</a>' +
                        ' <a href="javascript:void();" onclick="deleteImage('+msg.id+ ',\''+msg.filename+ '\', \'{id}\')">Delete</a>'
                );
                }
                //else $('<li></li>').appendTo('#files').text(response).addClass('error');
            }
        });

    });
</script>


<script type = "text/javascript">

    function setImageDefault(image_name, consultant_id){
        var url_request = "<?php echo site_url('admin/consultant/set_image/'); ?>";
        $.ajax({
            type: "POST",
            url: url_request ,
            data: "consultant_id=" + consultant_id + "&image_name="+ image_name ,
            dataType: "json",
            success: function(msg){
                //if(msg.error == false)
                //    $('#' + province_id).hide(1);

            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                // $('#waiting').hide(500);
                // $('#message').removeClass().addClass('error').text('There was an error.').show(500);
                // $('#demoForm').show(500);
                alert( "Error: " + textStatus.toString() + url_request);
            }
        });
    }


</script>

<form action="{base_url}admin/consultant/save" method="post" name="myform">
    <div class="box_function">
        <table width="747" border="0" cellpadding="0" cellspacing="0" class="listproduct" id="listproduct">
            <tr>
                <td colspan="2" style="padding:5px">
                    <h1>
                        {legend_text}
                    </h1>
                    {error_message}

                </td>
            </tr> 

            <tr>
                <td class="product">
                    <h5>Họ tên </h5>
                    <input type="text" style="width: 260px; height:20px" class="text" name="txtFullname" id="txtViName" value="{fullname}" maxlength="100" />
                </td>
                <td class="product" style="align:left">
                    <h5>Địa chỉ</h5>
                    <input type="text" style="width: 260px; height:20px" class="text" name="txtAddress" id="txtViName" value="{address}" maxlength="100" />
                </td>
            </tr>

            <tr>

                <td class="product">
                    <h5>Email:</h5>
                    <input type="text" style="width: 260px; height:20px" class="text" name="txtEmail" id="txtFriendlyURL" value="{email}" maxlength="100" />
                </td>
                <td class="product">
                    <h5>Điện thoại:</h5>
                    <input type="text" style="width: 260px; height:20px" class="text" name="txtPhone" id="txtFriendlyURL" value="{phone}" maxlength="100" />
                </td>
            </tr>
            
            <tr>

                <td class="product">
                    <h5>Fax:</h5>
                    <input type="text" style="width: 260px; height:20px" class="text" name="txtFax" id="txtFriendlyURL" value="{fax}" maxlength="100" />
                </td>
                <td class="product">
                    <h5>Tiêu đề:</h5>
                    <input type="text" style="width: 260px; height:20px" class="text" name="txtTitle" id="txtFriendlyURL" value="{title}" maxlength="100" />
                </td>
            </tr>

            <tr>
                <td class="product" colspan="2">
                    <h5>Câu hỏi:</h5>
                    <textarea rows="5" cols="90" class="text" name="txtQuestion" id="txtViSummary" >{question}</textarea>
                </td>
            </tr>


            <tr>
                <td class="product" colspan="2">
                    <h5>Hình ảnh:</h5>
                    <script>
                        function insert(file, location){
                            
                                CKEDITOR.instances.txtAnswer.insertHtml("<img align='absmiddle' src='{base_url}data/images/upload/"+file+"'>");
                            
                        }
                    </script>

                    <div id="files" >
                        {images}
                        <div class ="success" id="{image_id}"> <img src="{base_url}data/images/upload/{vi_file_name}" alt="" /><br />
                            <a href="javascript:void();" onclick="insert('{vi_file_name}', 'vi');">Insert</a>
                            <a href="javascript:void();" onclick="setImageDefault('{vi_file_name}', {id});">Default</a>
                            <a href="javascript:void();" onclick="deleteImage({image_id},'{vi_file_name}', {id})">Delete</a>
                        </div>
                        {/images}
                    </div>

                    <div style="clear:both"></div>
                    <div id="upload" ><span>Upload File<span></div>
                                <span id="status" ></span>

                                </td>
                                </tr>

                                <tr>
                                    <td class="product" colspan="2">
                                        <h5>Nội dung:</h5>
                                        <?php echo $this->ckeditor->editor("txtAnswer", $answer, $config); ?>
                                    </td>
                                </tr>

                                <tr>
                                    <td style="padding: 5px" colspan="2">
                                        <h5>

                                            <span>{ckActive}<?php echo lang('active') ?></span>
                                        </h5>
                                    </td>
                                </tr>


                                <tr>
                                    <td></td>
                                    <td>
                                        <?php echo lang('indicates_a_required_field'); ?>
                                    </td>
                                </tr>

                                <tr>
                                    <td class="product"> <input type="submit" class="submit button" name="btSave" value="<?php echo lang('save') ?>" /></td>
                                    <td>
                                       
                                    </td>
                                </tr>
                                </table>
                                </div>
                                <input type="hidden" name="txtID" id="txtID" value="{id}"/>
                                <input type="hidden" name="txtPosition" id="txtPosition" value="{position}"/>
                                
                                </form>